
// Copyright (C) 2007 Richard Uhler
// This file is part of Esiply.
//
// Esiply is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, Version 2,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include "JanusFunction.h"
#include "Null.h"

JanusFunction::JanusFunction(Function* call, Function* construct)
    : m_call(call), m_construct(construct)
{
    // For a JanusFunction we just take the length to be the length
    // of the call function.
    this->put(new String("length"), m_call->get(new String("length")),
            PA_DONT_DELETE | PA_READ_ONLY | PA_DONT_ENUM);
}

Value* JanusFunction::call(Scope* scope, Value* this_obj, List* args)
{
    return m_call->call(scope, this_obj, args);
}

Value* JanusFunction::construct(List* args)
{
    return m_construct->call(NULL, Null::null, args);
}

